import pygame

class score_bar:
    def __init__(self, game):
        self.game = game
        self.game_logic = game.game_logic
        self.player = game.game_logic.local_player
        
        pygame.font.init()
        self.font = pygame.font.Font("data/fonts/Arial.ttf", 20)
        
        self.dirty = True
        self.image = None
        self.rect = None
        self._draw_bar()
    
    def _draw_bar(self):
        kPic = pygame.image.load("data/kills_icon.png")
        aPic = pygame.image.load("data/assists_icon.png")
        dPic = pygame.image.load("data/deaths_icon.png")
        self.image = pygame.Surface((96, 64))
        self.image.fill((255, 0, 255))
        self.image.set_colorkey((255, 0, 255))
        self.rect = self.image.get_rect()
        
        self.image.blit(kPic, kPic.get_rect())
        self.image.blit(aPic, kPic.get_rect().move(32, 0))
        self.image.blit(dPic, kPic.get_rect().move(64, 0))
        
        kNum = self.font.render(str(self.player.kills), False, (0,0,0), (255, 0, 255))
        kNMove = (32 - kNum.get_rect().w) / 2
        aNum = self.font.render(str(self.player.assists), False, (0,0,0), (255, 0, 255))
        aNMove = (32 - aNum.get_rect().w) / 2
        dNum = self.font.render(str(self.player.deaths), False, (0,0,0), (255, 0, 255))
        dNMove = (32 - dNum.get_rect().w) / 2
        
        self.image.blit(kNum, kNum.get_rect().move(kNMove, 32))
        self.image.blit(aNum, kNum.get_rect().move(32+aNMove, 32))
        self.image.blit(dNum, kNum.get_rect().move(64+dNMove, 32))
        
        self.rect.bottom = self.game_logic.screen_rect.bottom - 15
        self.rect.left = self.game_logic.screen_rect.w - 106
    
    def update(self):
        if not self.dirty:
            return
        
        self._draw_bar()
